package com.sibu.yx.promotion.web.support.selector;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.boot.autoconfigure.AutoConfigurationImportSelector;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.Assert;

/**
 * @author yuwenbo
 * @create 2019-04-02 11:43
 **/
public class CustomAutoConfigurationImportSelector extends AutoConfigurationImportSelector {

    @Override
    protected List<String> getCandidateConfigurations(AnnotationMetadata metadata,
                                                      AnnotationAttributes attributes) {

        Map<String, Object> map=metadata.getAnnotationAttributes(CustomEnableAutoConfiguration.class.getName(),false);
        Class[] classes =(Class[])map.get("value");
        Assert.notEmpty(classes,
                "No auto configuration classes found in META-INF/spring.factories. If you "
                        + "are using a custom packaging, make sure that file is correct.");
        List<String> configurations=new ArrayList<>(classes.length);
        for(Class classez:classes){
            configurations.add(classez.getName());
        }
        return configurations;
    }
}
